﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QLKS.Templates;

namespace QLKS.Views
{
    /// <summary>
    /// Interaction logic for frmRegister.xaml
    /// </summary>
    public partial class frmRegister : FormTrans
    {
        public bool IsRegisted = false;
        public frmRegister()
        {
            InitializeComponent();
            txtId.Text = ViewModels.RegisterViewModel.GetID();            
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (txtId.Text.Trim() == "")
            {
                MessageBox.Show(M_LAN.Equals("V")?"Chưa nhập tên người đăng ký!":"Input username, please", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                txtId.Focus();
                return;
            }
            IsRegisted = ViewModels.RegisterViewModel.Register(txtId.Text, txtSerial.Text);

            if (!IsRegisted)
            {
                MessageBox.Show(M_LAN.Equals("V")?"Mật khẩu nhập lại không khớp!":"Confirm password not match", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                txtSerial.Focus();
                return;
            }
            MessageBox.Show(M_LAN.Equals("V")?"Đăng ký thành công!":"Register sussessful", "Success");
            ViewModels.RegisterViewModel.WriteLic(txtSerial.Text, "Key.lic");
            this.Close();
        }

        private void FormTrans_Loaded(object sender, RoutedEventArgs e)
        {
            txtSerial.Focus();
        }
    }
}
